import json
import uuid

from utils.MAC import get_mac_address


# 问卷模版

class QTemplate:
    def __init__(self, name, num_questions, questions, timer_duration):
        # 问卷名
        self.template_name = name
        # 问卷创建者ID MAC地址
        self.creator_id = get_mac_address()
        # 问题数
        self.num_questions = num_questions
        # 问题
        self.questions = questions
        # 截止时间
        self.timer_duration = timer_duration
        # 问卷ID
        self.template_uuid = None
        # 创建问卷日期
        self.created_time = None

    # 设置和获取问卷名
    def set_template_name(self, name):
        self.template_name = name
        return name
    def get_template_name(self):
        return self.template_name


    # 设置和获取创建者ID
    def set_creator_id(self, creator_id):
        self.creator_id = creator_id
        return creator_id

    def get_creator_id(self):
        return self

    # 设置和获取问题数
    def set_num_questions(self, num_questions):
        self.num_questions = num_questions
        return self

    def get_num_questions(self):
        return self.num_questions


    # 设置和获取问题
    def set_questions(self, questions):
        self.questions = questions
        return self

    def get_questions(self):
        return self.questions


    # 设置和获取截止时间
    def set_timer_duration(self, timer_duration):
        self.timer_duration = timer_duration
        return self

    def get_timer_duration(self):
        return self.timer_duration


    # 设置和获取问卷ID

    def set_template_uuid(self, template_uuid):
        self.template_uuid = template_uuid

    def get_template_uuid(self):
        return self.template_uuid

    # 设置和获取创建问卷日期
    def set_created_time(self, created_time):
        self.created_time = created_time
    def get_created_time(self):
        return self.created_time

    # 获取对象JSON格式
    def get_template_json_formate(self):
        return json.dumps(
            {
                "template_name": self.template_name,
                "creator_id": self.creator_id,
                "num_questions": self.num_questions,
                "questions":self.questions,
                "timer_duration": self.timer_duration,
                "template_uuid": self.template_uuid,
                "created_time": self.created_time
            },
            ensure_ascii=False
        )

